package com.pai.servlet.Select;

import com.alibaba.fastjson.JSON;
import com.pai.entity.AppUser;
import com.pai.entity.Department;
import com.pai.entity.vmodel.UserInfo;
import com.pai.service.AppUser.AppUserService;
import com.pai.service.AppUser.AppUserServiceImpl;
import com.pai.service.Department.DepartmentService;
import com.pai.service.Department.DepartmentServiceImpl;
import com.pai.servlet.BaseServlet;
import com.pai.vo.ApiResult;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "selectOptionServlet",urlPatterns = {"/selectOption"})
public class SelectOptionServlet extends BaseServlet {
    private DepartmentService departmentService;  //部门服务层

    @Override
    public void init() throws ServletException {
        super.init();
        this.departmentService = new DepartmentServiceImpl();
    }
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ApiResult apiResult = new ApiResult();

        try{
            String opType =req.getParameter("opType");
            switch (opType){
                case "class":
                    String depId = req.getParameter("depId");
                    String roleId = req.getParameter("roleId");
                    String pensonId = req.getParameter("pensonId");
                    List<Department> list = departmentService.getClassOptions(depId, roleId, pensonId);
                    apiResult.setData(list);
                    break;
                default:
            }
        }catch (Exception e){
            e.printStackTrace();
            apiResult.setError();
        }finally {
            write(resp, apiResult);
        }
    }


}
